/**
 * 栈： FILO， 先入后出
 */

class Stack {
    constructor() {
        this.count = 0
        this.items = {}
    }

    // 将数据压入栈
    push(item) {
        this.items[this.count] = item
        this.count ++
    }

    pop(){
        const result = this.items[this.count-1]
        delete this.items[this.count-1]
        this.count --
        return result
    }
    peek() {
        return this.items[this.count-1]
    }
    isEmpty() {
        return this.count === 0
    }

    size() {
        return this.count;
    }

    clear() {
        this.count = 0
        this.items = {}
    }

}

const  stack = new Stack()
stack.push('one')
stack.push('two')
stack.push('three')
stack.push('four')
stack.push('five')
stack.push('six')
stack.push('seven')
console.log(stack)
console.log(stack.size())

stack.pop()
console.log(stack)
stack.pop()
console.log(stack)
console.log(stack.size());


console.log(stack.isEmpty());
// stack.clear()
console.log(stack.isEmpty());
console.log(stack);

console.log(stack.peek());
console.log(stack)

